<template>
  <div>
    <DetailBanner :sightName="sightName" :bannerImg="bannerImg" :bannerImgs="gallaryImgs"></DetailBanner>
    <DetailHeader></DetailHeader>
    <div class="ss">
      <DetailList :list="list"></DetailList>
    </div>
  </div>
</template>

<script>
import DetailBanner from './components/Banner'
import DetailHeader from './components/Header'
import DetailList from './components/List'
import axios from 'axios'
export default {
  name: 'Detail',
  components: {
    DetailBanner,
    DetailHeader,
    DetailList
  },
  data () {
    return {
      sightName: '',
      bannerImg: '',
      gallaryImgs: [],
      list: []
    }
  },
  methods: {
    getDetailIfon () {
      axios.get('http://localhost:3000', {
        params: { // 绑定id
          id: this.$route.params.id
        }
      }).then(this.handleGetDataSucc)
    },
    handleGetDataSucc (res) {
      res = res.data
      if (res.ret && res.data) {
        const data = res.data
        this.sightName = data.sightName
        this.bannerImg = data.bannerImg
        this.gallaryImgs = data.gallaryImgs
        this.list = data.categoryList
      }
    }
  },
  // 钩子函数 当进入新的页面 id也要跟着变化 同时获取id相应的数据
  mounted () {
    this.lastId = this.$route.params.id
    this.getDetailIfon()
  },
  activated () {
    if (this.lastId !== this.$route.params.id) {
      this.lastId = this.$route.params.id
      this.getDetailIfon()
    }
  }
}
</script>

<style scoped>
  .ss{
    height: 15rem;
  }
</style>
